<?php

namespace app\index\controller;

use app\index\model\WechatOrder;
use think\Controller;

class Index extends Controller
{

    public function test()
    {
        $username = $this->request->get('username');
        echo '您得用户名为' . $username;
    }

    public function index()
    {

        return $this->fetch(__FUNCTION__, []);
    }

    public function getWechatOrder()
    {

        $param = $this->request->param();
        $where = '';
        if (isset($param['id']) && !empty($param['id'])) {
            $where .= 'id = "' . $param['id'] . '"';
        }
        if (isset($param['order_id']) && !empty($param['order_id'])) {
            if ($where) {
                $where .= 'and order_id = "' . $param['order_id'] . '"';
            } else {
                $where .= 'order_id = "' . $param['order_id'] . '"';
            }
        }
        if (isset($param['order_tunnel_id']) && !empty($param['order_tunnel_id'])) {
            if ($where) {
                $where .= 'and order_tunnel_id = "' . $param['order_tunnel_id'] . '"';
            } else {
                $where .= 'order_tunnel_id = "' . $param['order_tunnel_id'] . '"';
            }
        }
        $wechatOderModel = new WechatOrder();
        $wechatOrders = $wechatOderModel->where($where)->paginate($this->request->get('limit'));
        $wechatOrders = $wechatOrders->toArray();
        $result['code'] = 0;
        $result['count'] = $wechatOrders['total'];
        $result['data'] = $wechatOrders['data'];
        return json($result);
    }

    public function employee($name)
    {
        return $name;
    }
}
